* Apply to:  sfmay_1_scores.csv
* Description:  Plot ideal points of 2011 mayoral candidates

clear
set more off


import delimited "...\1805 Roadmaps\Figures A7 and A8\sfmay_1_scores.csv", delimiter(comma)


* Fix variable names

rename v1 name
rename v2 party


* Define faction

gen faction = "None"

replace faction = "Moderate" if name=="Alioto-Pier"
replace faction = "Moderate" if name=="Hall"
replace faction = "Moderate" if name=="Lee"
replace faction = "Moderate" if name=="Herrera"
replace faction = "Moderate" if name=="Dufty"
replace faction = "Moderate" if name=="Rees"

replace faction = "Progressive" if name=="Baum"
replace faction = "Progressive" if name=="Avalos"
replace faction = "Progressive" if name=="Currier"
replace faction = "Progressive" if name=="Yee"
replace faction = "Progressive" if name=="Adachi"
replace faction = "Progressive" if name=="Chiu"


* Fix coord1d variable

drop if name=="Ascarrunz"

rename coord1d coord1d_text

destring coord1d_text, gen(coord1d)
drop coord1d_text


* Define rank

sort coord1d

gen rank = _n


twoway scatter rank coord1d if faction=="Moderate", ///
     mcolor(navy) msymbol(s) msize(large) || ///
     scatter rank coord1d if faction=="Progressive", ///
	 mcolor(maroon) msymbol(t) msize(large) || ///
	 scatter rank coord1d if faction=="None", ///
	 mcolor(black) msymbol(O) msize(large) ///
     xlabel(-1(.5)1) xmlabel(-1.2(.5)1.2, notick nolabel) ///
	 xtitle(" " "{bf:Progressive-Moderate Dimension}") ///
	 ylabel(1(1)15) ymlabel(0(1)15.5, nolabel) ///
	 ytitle("{bf:Rank}" " ") ///
     xline(.48, lcolor(gs10)) ///
	 text(13 -.50 "{bf:Oppose Sit-Lie Policy}", color(gs10) size(medsmall)) ///
	 text(4 .90 "{bf:Favor Sit-Lie Policy}", color(gs10) size(medsmall)) ///
 	 text(1 -.95 "{bf:Baum}", color(maroon) size(medsmall) placement(e)) ///
 	 text(2 -.63 "{bf:Avalos}", color(maroon) size(medsmall) placement(w)) ///
 	 text(3 -.40 "{bf:Currier}", color(maroon) size(medsmall) placement(e)) ///
 	 text(4 -.25 "{bf:Yee}", color(maroon) size(medsmall) placement(w)) ///
 	 text(5 0 "{bf:Adachi}", color(maroon) size(medsmall) placement(w)) ///
 	 text(6 .21 "{bf:Pang}", color(black) size(medsmall) placement(w)) ///
 	 text(7 .21 "{bf:Chiu}", color(maroon) size(medsmall) placement(w)) ///
 	 text(8 .25 "{bf:Rees}", color(navy) size(medsmall) placement(w)) ///
 	 text(9 .26 "{bf:Ting}", color(black) size(medsmall) placement(w)) ///
 	 text(10 .38 "{bf:Herrera}", color(navy) size(medsmall) placement(w)) ///
 	 text(11 .69 "{bf:Dufty}", color(navy) size(medsmall) placement(e)) ///
 	 text(12 .90 "{bf:Lawrence}", color(black) size(medsmall) placement(e)) ///
 	 text(13 .84 "{bf:Lee}", color(navy) size(medsmall) placement(w)) ///
 	 text(14 .98 "{bf:Hall}", color(navy) size(medsmall) placement(e)) ///
 	 text(15 .95 "{bf:Alioto-Pier}", color(navy) size(medsmall) placement(w)) ///
	 legend(off) plotregion(margin(zero) color(white)) graphregion(color(white))

* End
